/**
 * 
 */
package com.xb.demo22.command;

import java.util.LinkedList;
import java.util.List;

/**
 * @author kexue
 *
 */
public class CommandStack {

	/**
	 * 命令stack
	 */
	private List<Command> stack = new LinkedList<Command>();

	public void execute() {
		if (stack.size() > 0) {
			for (Command command : stack) {
				command.execute();
			}
		}
	}

	public void addCommand(Command command) {
		stack.add(command);
	}

	public void undoCommand() {
		if (stack.size() > 0)
			stack.remove(stack.size() - 1);
	}

	/**
	 * 
	 */
	public void clear() {
		stack.clear();
	}
}
